package com.smart.community.commons.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

/**
 * 删除标记枚举类
 * 统一管理系统中的删除标记
 * @author Wu.Liang
 * @since 2025-01-29
 */
public enum DeletedEnum {
    NOT_DELETED(0, "未删除"),
    DELETED(1, "已删除");

    @JsonValue
    private final Integer code;
    private final String description;

    DeletedEnum(Integer code, String description) {
        this.code = code;
        this.description = description;
    }

    public Integer getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据代码获取枚举
     */
    public static DeletedEnum getByCode(Integer code) {
        for (DeletedEnum deleted : values()) {
            if (deleted.getCode().equals(code)) {
                return deleted;
            }
        }
        return null;
    }

    /**
     * 检查是否为删除状态
     */
    public static boolean isDeleted(Integer code) {
        return DELETED.getCode().equals(code);
    }

    /**
     * 检查是否为未删除状态
     */
    public static boolean isNotDeleted(Integer code) {
        return NOT_DELETED.getCode().equals(code);
    }
    
    /**
     * Jackson反序列化方法
     * 严格遵循《系统状态枚举权威标准声明.md》规范
     * 
     * @param code 枚举值
     * @return 对应的枚举，如果不存在则返回null
     */
    @JsonCreator
    public static DeletedEnum fromCode(Integer code) {
        return getByCode(code);
    }
}
